package com.ceair.flight.refund.location.dt.enums;

import java.util.Arrays;
import java.util.List;

/**
 *
 * @author youguilin
 */
public enum RefundStatus {

    SUBMIT_APPLY("101", "提交申请"),
    REFUND_TICKET_EXCEPTION("109", "退票异常"),
    WAIT_FIRST_AUDIT("201", "等待审核"),
    WAIT_USER_UPDATE("2011", "等待用户更新"),
    FIRST_AUDIT_EXCEPTION("209", "一审异常"),
    WAIT_SECOND_AUDIT("301", "等待二审"),
    SECOND_AUDIT_REFUSE("3011", "等待审核(二审拒绝)"),
    SECOND_AUDIT_PASS("302", "二审通过"),
    WAITING_CARD_FOR_REFUND_NO("308", "等待用户支付卡信息,生成退票单号"),
    GENERATE_REFUND_NO_EXCEPTION("309", "生成退票单号异常"),
    WAIT_MONEY_REFUND("401", "等待退款"),
    MONEY_REFUNDING("402", "退款中"),
    MONEY_REFUND_EXCEPTION("409", "退款异常"),
    MONEY_REFUND_SUCCESS("501", "退款成功"),
    REFUNDED_DONE("901", "退票完成"),
    DELETED("909", "已删除"),
    //用户在订单中看到的退票状态
    VIEW_WAITING_UPDATE("600", "等待用户更新"),
    VIEW_REFUNDING("700", "退票中"),
    VIEW_WAITING_REFUND_MONEY("800", "退款中"),
    VIEW_REFUNDED("900", "退票完成");

    //等待用户更新状态列表
    private static final RefundStatus[] VIEW_WAITING_UPDATE_LIST = new RefundStatus[]{WAIT_USER_UPDATE};
    //退票中状态列表
    private static final RefundStatus[] VIEW_REFUNDING_LIST = new RefundStatus[]{WAIT_FIRST_AUDIT, FIRST_AUDIT_EXCEPTION, WAIT_SECOND_AUDIT,
            SECOND_AUDIT_REFUSE, SECOND_AUDIT_PASS, WAITING_CARD_FOR_REFUND_NO, GENERATE_REFUND_NO_EXCEPTION, WAIT_MONEY_REFUND, MONEY_REFUND_EXCEPTION};
    //退票完成状态列表
    private static final RefundStatus[] VIEW_REFUNDED_LIST = new RefundStatus[]{REFUNDED_DONE, MONEY_REFUND_SUCCESS};
    //等待用户更新状态列表
    private static final List<RefundStatus> WAITING_UPDATE_LIST = Arrays.asList(VIEW_WAITING_UPDATE_LIST);
    //退票中状态列表
    private static final List<RefundStatus> REFUNDING_LIST = Arrays.asList(VIEW_REFUNDING_LIST);
    //退票完成状态列表
    private static final List<RefundStatus> REFUNDED_LIST = Arrays.asList(VIEW_REFUNDED_LIST);

    /**
     * 简码
     */
    private final String code;

    /**
     * 描述
     */
    private final String description;

    private RefundStatus(String code, String description) {
        this.code = code;
        this.description = description;
    }

    /**
     * @return Returns the code.
     */
    public String getCode() {
        return code;
    }

    /**
     * @return Returns the description.
     */
    public String getDescription() {
        return description;
    }

    /**
     * 通过枚举<code>code</code>获得枚举。
     *
     * @param code 简码
     * @return 枚举
     */
    public static RefundStatus getByCode(String code) {
        for (RefundStatus status : values()) {
            if (status.getCode().equals(code)) {
                return status;
            }
        }
        return null;
    }

    public static RefundStatus getViewStatus(RefundStatus refundStatus) {
        if (WAITING_UPDATE_LIST.contains(refundStatus)) {
            return VIEW_WAITING_UPDATE;
        } else if (REFUNDING_LIST.contains(refundStatus)) {
            return VIEW_REFUNDING;
        } else if (REFUNDED_LIST.contains(refundStatus)) {
            return VIEW_REFUNDED;
        }
        return null;
    }
}
